PROGRAM CCSD
!
! INCORE PROGRAM FOR CCSD CALCULATIONS 
!
use mod_iop
use mod_symm
use mod_orbit
use mod_size
implicit none
integer prec2, isd2, igpu2, totgpu2
common/precsoc/prec2, isd2, igpu2, totgpu2
integer nvn, non, i0
integer ie, iend, ifij, ifab
integer ifia, it1, it2, iijkl, iijka 
integer it12, it22, ir12, ir22, iend2
integer iiabj, iabij, iabci, iabcd, ir1, ir2
integer ifmi, ifae, ifme
integer iwmnij, iwmbej
integer maxcore, nneed, i1
integer, external :: irpdso, idsymsoc
real*8 tt1, tt2, rt1, rt2
real*8 escf, eccsd, eccsdt
real*4, allocatable :: icore(:) 
!
call cpu_time(tt1); call walltimeso(rt1)
call read_mod
write(6,*)'finished read mod'
!icrsiz = 1024*1024*1024*80/8
prec2=prec; isd2=isd;  igpu2=igpu; totgpu2=totgpu
allocate(icore(icrsiz))
!goto 1000
if(prec==8) then
  write(6,*)'begin clmoio AA term' 
  call clmoioso0(1, icore, popa, popa, 0, popa, popa, 0,  'IJKLAA__')
  call getallso(icore, 1, 'IJKLAB__')
  i1 = i0 + idsymsoc(1, popa, popa, 1, pop, popa, 1)*isd
  call iassymso(icore, icore(i1), 1, popa, popa, popa, popa, 5)
  call icompso(icore(i1), icore, popa, popa,0,1, popa, popa,1,0,1)
  call putallso(icore, 1, 'IJKLAA__')
  
  call clmoioso0(1, icore, popa, popa, 0, popa, vrta, 1,  'IJKAAA__')
  i1 = 1 + idsymsoc(1, vrta, popa, 1, popa, popa, 1)*isd
  call getallso(icore, 1, 'IJKAAB__')
  call iassymso(icore, icore(i1), 1, popa, popa, popa, vrta, 5)
  call putallso(icore(i1), 1, 'IJKAAA__')
! 
  call clmoioso0(1, icore, vrta, vrta, 0, popa, popa, 0,  'T2AA____')
  i1 = 1 + idsymsoc(1, vrta, vrta, 1, popa, popa, 1)*isd
  call getallso(icore, 1, 'T2AB____')
  call iassymso(icore, icore(i1), 1, vrta, vrta, popa, popa, 5)
  call icompso(icore(i1), icore, vrta, vrta,0,1, popa, popa,1,0,1)
  call putallso(icore, 1, 'T2AA____')

  call clmoioso0(1, icore, vrta, vrta, 0, popa, popa, 0,  'ABIJAA__')
  i1 = 1 + idsymsoc(1, vrta, vrta, 1, popa, popa, 1)*isd
  call getallso(icore, 1, 'ABIJAB__')
  call iassymso(icore, icore(i1), 1, vrta, vrta, popa, popa, 5)
  call icompso(icore(i1), icore, vrta, vrta,0,1, popa, popa,1,0,1)
  call putallso(icore, 1, 'ABIJAA__')
! 
  call clmoioso0(1, icore, vrta, vrta, 0, vrta, popa, 1,  'ABCIAA__')
  call getallso(icore, 1, 'ABCIAB__')
  i1 = 1 + idsymsoc(1, vrta, vrta, 1, vrta, popa, 1)*isd
  call iassymso(icore, icore(i1), 1, vrta, vrta, vrta, popa, 5)
  call putallso(icore(i1), 1, 'ABCIAA__')
elseif(prec==4) then 
  call clmoioso0_s(1, icore, popa, popa, 0, popa, popa, 0,  'IJKLAAS_')
  call getallso_s(icore, 1, 'IJKLABS_')
  i1 = i0 + idsymsoc(1, popa, popa, 1, pop, popa, 1)*isd
  call iassymso(icore, icore(i1), 1, popa, popa, popa, popa, 5)
  call icompso(icore(i1), icore, popa, popa,0,1, popa, popa,1,0,1)
  call putallso_s(icore, 1, 'IJKLAAS_')
  
  call clmoioso0_s(1, icore, popa, popa, 0, popa, vrta, 1,  'IJKAAAS_')
  i1 = 1 + idsymsoc(1, vrta, popa, 1, popa, popa, 1)*isd
  call getallso_s(icore, 1, 'IJKAABS_')
  call iassymso(icore, icore(i1), 1, popa, popa, popa, vrta, 5)
  call putallso_s(icore(i1), 1, 'IJKAAAS_')

  call clmoioso0(1, icore, vrta, vrta, 0, popa, popa, 0,  'T2AAS___')
  i1 = 1 + idsymsoc(1, vrta, vrta, 1, popa, popa, 1)*isd
  call getallso(icore, 1, 'T2ABS___')
  call iassymso(icore, icore(i1), 1, vrta, vrta, popa, popa, 5)
  call icompso(icore(i1), icore, vrta, vrta,0,1, popa, popa,1,0,1)
  call putallso(icore, 1, 'T2AAS___')
  
  call clmoioso0_s(1, icore, vrta, vrta, 0, popa, popa, 0,  'ABIJAAS_')
  i1 = 1 + idsymsoc(1, vrta, vrta, 1, popa, popa, 1)*isd
  call getallso_s(icore, 1, 'ABIJABS_')
  call iassymso(icore, icore(i1), 1, vrta, vrta, popa, popa, 5)
  call icompso(icore(i1), icore, vrta, vrta,0,1, popa, popa,1,0,1)
  call putallso_s(icore, 1, 'ABIJAAS_')
  
  call clmoioso0_s(1, icore, vrta, vrta, 0, vrta, popa, 1,  'ABCIAAS_')
  call getallso_s(icore, 1, 'ABCIABS_')
  i1 = 1 + idsymsoc(1, vrta, vrta, 1, vrta, popa, 1)*isd
  call iassymso(icore, icore(i1), 1, vrta, vrta, vrta, popa, 5)
  call putallso_s(icore(i1), 1, 'ABCIAAS_')
endif

!
! various lengths
!
1000 nvn = nva + nvb
non = noa + nob
!
ie=1
iend=ie+(nvn+non)*isd
!
!write(6,*)'norb', nva, noa, nvb, nob
!memory fo t1, t2 and r1, r2
it1 = iend
iend = it1 + nifvo*isd
write(6,*)'begin ccsdt calculation'
call ccsdt(icore, eccsdt)
!
end



















